/*
 * Copyright (C) 2011 Dirk Weißenborn, dirk.weissenborn@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.weissenborn.colabtex.server.user;

import java.io.Serializable;

import javax.persistence.Id;

/**
 * The persistence Class Permission which maps a role to a group name
 */
public class Permission implements Serializable{
	
	/** The group name. */
	@Id
	private String groupName;
	
	/** The role. */
	@Id
	private Role role;
	
	/**
	 * Instantiates a new permission.
	 */
	public Permission() { }
	
	/**
	 * Instantiates a new permission.
	 *
	 * @param groupName the group name
	 * @param role the role
	 */
	public Permission(String groupName, Role role) {
		this.groupName = groupName;
		this.role = role;
	}

	/**
	 * Gets the role.
	 *
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * Sets the role.
	 *
	 * @param role the new role
	 */
	public void setRole(Role role) {
		this.role = role;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Permission)
			return ((Permission)obj).groupName == groupName && ((Permission)obj).role == role;
		return super.equals(obj);
	}
	
	/**
	 * Gets the group name.
	 *
	 * @return the group name
	 */
	public String getGroupName() {
		return groupName;
	}

	/**
	 * Sets the group name.
	 *
	 * @param groupName the new group name
	 */
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	/**
	 * The Enum Role.
	 */
	public enum Role {
		
		/** The admin. */
		admin,
/** The editor. */
editor,
/** The reader. */
reader;
	}
	
}
